﻿#include <iostream>
#include <Shobjidl.h>
#include "Network.hpp"
#include "JsonPaser.hpp"
#include "StringUtils.hpp"

int main() {
    std::cout << "1.请求图片URL信息" << std::endl;

    std::string jsonString = getImagePath();

    std::cout << "2.解析图片URL信息" << std::endl;

    std::string imgPath = getImagePath(jsonString);

    std::cout << "3.下载图片" << std::endl;
    
    std::string filePath = downloadImage(imgPath);
    if (filePath.empty()) {
        std::cout << "--- 图片下载失败 ---" << std::endl;
        exit(-1);
    }

    std::cout << "4.设置壁纸" << std::endl;
    // string转wstring
    std::wstring filePahtW = String2WString(filePath);

    CoInitialize(NULL);
    IDesktopWallpaper* desktop;

    HRESULT result = CoCreateInstance(__uuidof(DesktopWallpaper), 0, CLSCTX_LOCAL_SERVER, __uuidof(IDesktopWallpaper), (void**)&desktop);
    if (SUCCEEDED(result)) {
        desktop->SetWallpaper(NULL, filePahtW.c_str());
        desktop->Release();

        std::cout << "--- 壁纸设置成功 ---" << std::endl;
    }

    CoUninitialize();

    getchar();

    return 0;
}
